import {Component, Input, OnInit} from '@angular/core';
import {Cargocate} from "../../../../model/admin/Cargocate";
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-hwlmedit',
  templateUrl: './hwlmedit.component.html',
  styleUrls: ['./hwlmedit.component.css']
})
export class HwlmeditComponent implements OnInit {
  @Input() optype:string;
  @Input() pid:string;
  t:Cargocate;
  constructor(private adminService:AdminService,
              private alertService:AlertService) {
    this.t = new Cargocate()
  }
  ngOnInit(): void {
    if(this.optype=='add'){
      this.t=new Cargocate();
      this.t.pid = this.pid
    }
    else if(this.optype=='update'){
      this.getReferTypeById();
    }

  }

  getReferTypeById(){
    this.adminService.getCargocateByid(this.pid)
      .then((data:any)=>{
        if(data.msg=='ok'){
          this.t=new Cargocate();
          this.t=data.obj;
        }
        else {
          this.alertService.showError('获取参考数据异常，请重试');
        }
      })
  }

  save(){

    this.adminService.saveCargocate(this.t)
      .then((data:any)=>{
        if(data.msg=='ok'){

        }
        else {
          this.alertService.showError('保存参考数据异常，请重试');
        }
      })
  }
}

